<?php
 class api{
     public $is_test = true;
     public $base_url = "http://atapi.guangwei.info";
     public $url_name = "";
     public $is_login = false;
     public $insert = array();

     public function __construct(){
         $app_token = "apptest";
         $random_str = time();
         $sign = md5(md5(md5($app_token.$random_str)));

         $apptype = "android";
         $appversion = "1.0";
         $insert  = array(
             'sign'=>$sign,
             'random_str'=>$random_str,
             'apptype'=>$apptype,
             'appversion'=>$appversion,
         );
         if($this->is_login){
             $insert['user_id'] = 2064;
             $insert['user_token'] = md5(md5(md5("2017-06-15 20:24:58android18260127042")));
         }
         $this->insert = $insert;
     }

     /**
      * curl post获取数据
      */

     function _post_url_post_data($data = array()){
         if($this->is_test){
             $url = $this->base_url."/api/".$this->url_name;
         }else{
             echo "暂未开启!";exit;
         }
         echo $url."</br>";
         echo time()."</br>";
         $data = array_merge($this->insert,$data);
         echo "<pre>";
         print_r($data);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         // post数据
         curl_setopt($ch, CURLOPT_POST, 1);
         // post的变量
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         $output = curl_exec($ch);
         curl_close($ch);

         echo $output;exit;
     }
 }

?>